// pages/detail-receiving/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address:[],
    user:{
      name:'',
      number:'',
      region:'',
      betailedregion:'',
      PostalCode:'',
      txtStyle:''
    },
    paste:'',
    paste2:""
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  xiao:function(){
      wx.chooseContact({
        success:function(res){
          console.log(res);
        },
        fail:function(red){
          console.log(red);
        },
        complete:function(aa){
          console.log(aa);
        }
      })
  },
  tongxun:function(){
    var that=this

    wx.chooseContact({
      success:function(res){
        that.data.user.name=res.displayName
        that.data.user.number=res.phoneNumber
        that.setData({user:that.data.user})
      },
      fail:function(red){
        wx.showToast({
          title: '模拟不支持调起',
          duration: 2000
      })
      },
      complete:function(aa){
        console.log(aa);
      }
    })
  },
  name:function(e){
    this.data.user.name=e.detail.value
    this.setData({user:this.data.user})

  },
  Number:function(e){
    this.data.user.number=e.detail.value
    this.setData({user:this.data.user})

  },
  kexiao:function(e){
    this.data.user.betailedregion=e.detail.value
    this.setData({user:this.data.user})

  },
  xiangxi:function(e){
    this.data.user.betailedregion=e.detail.value
    this.setData({user:this.data.user})

  },
  dingwei:function(){
    var that=this
    wx.chooseLocation({
      success:function(res){
        console.log(res);
        that.data.user.region=res.name
        that.data.user.betailedregion=res.address
        that.setData({user:that.data.user})
  },
  fail:function(red){
    console.log(red);
  }
})
  },
  bianma:function(e){
    this.data.user.PostalCode=e.detail.value
    this.setData({user:this.data.user})

  },
  dianjicheg:function(){
    var valueter = wx.getStorageSync('key'||'')
    var  username=[]
      if(this.data.user.name==''){
        wx.showToast({
          title: '名字还未填写',
          duration: 2000
      })
      }else if(this.data.user.number.length<11){
        wx.showToast({
          title: '手机号码还未填写',
          duration: 2000
      })
      }else if(this.data.user.region==''){
        wx.showToast({
          title: '地区还未填写',
          duration: 2000
      })
      }else if(this.data.user.betailedregion==''){
        wx.showToast({
          title: '地址还未填写',
          duration: 2000
      })
      }else if(this.data.user.PostalCode==''){
        wx.showToast({
          title: '邮政编码还未填写',
          duration: 2000
      })
      }else{
        this.setData({user:this.data.user})
        if(valueter==""){
          username.push(this.data.user)
          wx.setStorageSync('key',username)
        }else{
          console.log(valueter);
          valueter.forEach((res)=>{
            console.log(res);
            username.push(res)
          })
          username.push(this.data.user)
          console.log(username);
          wx.setStorage({
            key:"key",
            data:username
          })
        }
        wx.showToast({
          title: '添加成功',
          duration: 2000
      })
      wx.navigateBack({
        delta: 1,
      })
      // wx.
      }
  },
  shishiba:function(e){
    this.setData({paste:e.detail.value})
  },
  tian:function(){
    
   let xiao=this.data.paste.replace(/[\r\n]/g, " ");
   let kyi=xiao.split(" ")
   let xiang=[]
   kyi.forEach((a,b)=>{
    if(a!="收货人:"&&a!="手机号码:"&&a!="所在地区:"&&a!="详细地址:"){
     xiang.push(a)
    }
   })
   if(xiang!=""){
    this.data.user.name=xiang[0]
    this.data.user.number=xiang[1]
    this.data.user.region=xiang[2]
    this.data.user.betailedregion=xiang[3]
   }
   this.setData({user:this.data.user})
   this.setData({paste:this.data.paste2})
  },
  empty:function(){
    this.setData({paste:''})
  },
  shibie:function(){
     let str="赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤 滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵堪汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董粱杜阮蓝闵席季麻强贾路娄危江童颜郭 梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗宣丁贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄魏加封芮羿储靳汲邴糜松 井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘姜詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双 闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍郤璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东覃 殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后江红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊 澹台公冶宗政濮阳淳于仲孙太叔申屠公孙乐正轩辕令狐钟离闾丘长孙慕容鲜于宇文司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱 晋楚闫法汝鄢涂钦段干百里东郭南门呼延妫海羊舌微生岳帅缑亢况後有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福"
     let strqu="河北山西辽宁吉林黑龙江江苏浙江安徽福建江西山东河南湖北湖南广东海南四川贵州云南陕西甘肃青海台湾北京天津上海重庆广西内蒙古西藏宁夏新疆香港澳门"
     var uq= this.data.paste.slice(0,1)
     var kexiaol= this.data.paste.slice(0,2)
     if(str.indexOf(uq)!=-1&&strqu.indexOf(kexiaol)==-1){
    var kejin=[]
    var chagn=this.data.paste
    var ke=/^(.*?)(1[3-9][0-9]\d{8})(.*?)$/
    var kk=/(?<province>[^\x00-\xff]+省|.+自治区)(?<city>[^自治州]+自治州|[^市]+市|[^盟]+盟|[^地区]+地区|.+区划)(?<county>[^市]+市|[^县]+县|[^旗]+旗|[^区]+区)(?<village>.*)/
    var chenggg=chagn.split(ke)
    if(kejin==""){
      chenggg.forEach((res,index)=>{
        if(res!=""&&index!=3){
          kejin.push(res)
        }
      })
    }
    var yie=chenggg.join("")
    var hhh=yie.split(kk)
    hhh.forEach((res,index)=>{
      if(index!=0&&index!=5){
        kejin.push(res)
      }
    })
    console.log(kejin);
    let qwe=""
    this.data.user.name=kejin[0]
    this.data.user.number=kejin[1]
    qwe+=kejin[2]
    qwe+=kejin[3]
    qwe+=kejin[4]
    this.data.user.region=qwe
    this.data.user.betailedregion=kejin[5]
    this.setData({user:this.data.user})
     }else{
      wx.showToast({
        title: '格式不正确',
        icon:'none'
      })
     }


    // if(you==-1){
    //   console.log("没有省份");
    // }
    // for(let i=0;i<chagn.length;i++){
    //   var  xsiao= str.indexOf("广")
    //   console.log(xsiao);
    // }
    // let xiao=this.data.paste.replace(/[\r\n]/g, " ");
    // let kyi=xiao.split(" ")
    // let xiang=[]
    // kyi.forEach((a,b)=>{
    //  if(a!="收货人:"&&a!="手机号码:"&&a!="所在地区:"&&a!="详细地址:"){
    //    console.log(a);
    //   xiang.push(a)
    //  }
    // })
    // if(xiang!=""){
    //  this.data.user.name=xiang[0]
    //  this.data.user.number=xiang[1]
    //  this.data.user.region=xiang[2]
    //  this.data.user.betailedregion=xiang[3]
    // }
    // this.setData({user:this.data.user})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that=this
    wx.getClipboardData({
      success (res){
        console.log(res);
        wx.showToast({
          title: '复制成功',
          icon:'none'
        })
        that.data.paste=res.data
        that.setData({paste2:res.data})
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})